//
//  RegistViewController.m
//  xpkc
//
//  Created by TopSageOSX on 15/3/5.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "RegistViewController.h"

@interface RegistViewController ()

@end

@implementation RegistViewController{
    UIButton *botom_Btn;
    RegistView *registView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatRegistView];
}
- (void)creatRegistView{
    registView = [[RegistView alloc]initWithFrame:self.view.frame];
    registView.delegate = self;
    [self.view addSubview:registView];
}

#pragma mark - registerdelegate
- (void)registerWithUsername:(NSString *)username andPassword:(NSString *)password andEmail:(NSString *)email andPhone:(NSString *)phone{
    logdebug(@"注册");
    NSString *module = @"userLogin";
    NSString *interface = @"register";
    
    NSString *timeString = [GetTime getTime];
    NSString *hashString = [[NSString stringWithFormat:@"%@/%@/key/%@/time/%@",module,interface,KEY,timeString] md5];
    NSString *urlString = [NSString stringWithFormat:@"%@/laravel/public/%@/%@/hash/%@/appid/1",URL2,module,interface,hashString];
    
    NSDictionary *parameter = @{@"time":timeString,
                                @"userName":username,
                                @"userPWD":password,
                                @"reuserPWD":password,
                                @"email":email};
    
    logdebug(@"%@-----------",parameter);
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:urlString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        logdebug(@"%@",dic);
        [registView registStatue:RegistStatueSucc];
        [self.delegate fillUserName:username andPassWord:password];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        logdebug(@"%@",error.localizedDescription);
        [registView registStatue:RegistStatueNetError];
    }];
    
    
}
- (void)showUserProtocol{
    AgreementViewController *vc=[[AgreementViewController alloc]init];
    vc.title = @"用户协议";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
